/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cl.tienda.control;

import cl.tienda.modelo.Producto;
import java.io.IOException;
import java.io.PrintWriter;
import static java.lang.System.out;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 18735026-3
 */
public class ServletCConProd extends HttpServlet {

   
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       doPost(request, response);
    }

    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            PrintWriter out = response.getWriter();
        //Obtengo todoslos datos de la sesion de usuario 
            Vector<Producto> productos=(Vector<Producto>)request.getSession().getAttribute("productos"); 
            
        
        
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Consultar Producto</title>");            
            out.println("</head>");
            out.println("<body bgcolor='#FFFF90'>");
            out.println("<table border='1' bordercolor='#FB040C' align='center' cellpadding='0' cellspacing='0' width='50%'  bgcolor='red'>");
            out.println("<tr>");
            out.println("<td colspan='3' bgcolor='white'><center><img src='img/carro.jpg'></center></td>");
            out.println("<td colspan='3'><strong><center><H2><font color='white'>Carrito de Compras con Sesiones y Vectores</font></H2></center></strong></td>");
            out.println("</tr>");
            out.println("</table>");
            out.println("<table align='center' height='100'>");
            out.println("<tr>");
            out.println("<td align='right' valign='top'><a href='/CarritoCompras/ServletCConProd'>Consultar Productos</a> |</td>");
            out.println("<td align='right' valign='top'><a href='/CarritoCompras/ServletCAgrCarrito1'>Agregar al Carrito</a> |</td>");
            out.println("<td align='right' valign='top'><a href=''>Salir</a></td>");
            out.println("<td></td>");
            out.println("<td></td>");
            out.println("</tr>");
            out.println("</table>");
            
            out.println("<table border='1' bordercolor='#FB040C' align='center' cellpadding='0' cellspacing='0' width='50%'>");
                        
	    out.println("<tr>");
            out.println("<td colspan='3' bgcolor='#FF7721' style= 'width: 60%'  height='40'><strong><font color='white'>Nombre</font></strong></td>");
            out.println("<td colspan='3' bgcolor='#FF7721' style= 'width: 20%'  height='40' align='right'><strong><font color='white'>Stock</font></strong></td>");
            out.println("<td colspan='3' bgcolor='#FF7721' style= 'width: 20%'  height='40' align='right'><strong><font color='white'>Precio</font></strong></td>");
            out.println("</tr>");
            
             for(int i=0; i<productos.size(); i++)
             { 
                 if(i%2==0){ 
            out.println("<tr bgcolor='#FFFFFF'>"); 
            out.println("<td colspan='3' style= 'width: 60%'>" + productos.get(i).getNombreProducto() + "</td>"); 
            out.println("<td colspan='3' style= 'width: 20%' align='right' valign='top'>"+ productos.get(i).getStock() +"</td>"); 
            out.println("<td colspan='3' style= 'width: 20%' align='right' valign='top'>"+ productos.get(i).getPrecio() +"</td>");
            out.println("</tr>"); 
            }else{ 
            out.println("<tr>"); 
            out.println("<td colspan='3' style= 'width: 60%'>" + productos.get(i).getNombreProducto() + "</td>"); 
            out.println("<td colspan='3' style= 'width: 20%' align='right' valign='top'>"+ productos.get(i).getStock() +"</td>"); 
            out.println("<td colspan='3' style= 'width: 20%' align='right' valign='top'>"+ productos.get(i).getPrecio() +"</td>");
            out.println("</tr>"); 

            
        }
       }
           out.println("</table>");
            out.println("</body>");
            out.println("</html>");
            out.close();
    }

    /**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
